package com.inforim.module;

import java.util.ArrayList;
import java.util.List;

public class CSVObject {
	CogObject cogObject;
	List<CogRole> cogRoles=new ArrayList<CogRole>();
	public CogObject getCogObject() {
		return cogObject;
	}
	public void setCogObject(CogObject cogObject) {
		this.cogObject = cogObject;
	}
	public List<CogRole> getCogRoles() {
		return cogRoles;
	}
	public void setCogRoles(List<CogRole> cogRoles) {
		this.cogRoles = cogRoles;
	}
	public void addCogRole(CogRole cogRole){
		cogRoles.add(cogRole);
	}
	//path cognosrole sedrole name mudid
	@Override
	public String toString() {
		// TODO Auto-generated method stub
		String searchPath=null;
		String isdisabled=null;
		if(cogObject!=null){
			searchPath=cogObject.getPath();
			isdisabled=cogObject.getDisabled().toString();
		}
		String output=addCsv(searchPath);
		output+=addCsv(isdisabled);
		for(int i=0;i<cogRoles.size();i++){
			CogRole cogRole=cogRoles.get(i);
			if(i>0&&!searchPath.equals("")){
				output+=addCsv(searchPath);
				output+=addCsv(isdisabled);
			}
			output+=addCsv(cogRole.getCogName());
			output+=addCsv(cogRole.getSedName());
			for(int j=0;j<cogRole.getCogAccounts().size();j++){
				CogAccount account=cogRole.getCogAccounts().get(j);
				if(j>0){
					output+="\r\n";
					output+=addCsv(searchPath)+addCsv(isdisabled)+addCsv(cogRole.getCogName())+addCsv(cogRole.getSedName());
				}
				output+=addCsv(account.getName())+addCsv(account.getMudid());
			}
			if(cogRole.getCogAccounts().size()==0){
				output+=addCsv("");
				output+=addCsv("");
			}
			output+="\r\n";
		}
		output=output.replace(",\r\n","\r\n");
		return output;
	}
	private String addCsv(String content) {
		if(content==null)return "";
		return "\""+content+"\",";
	}
}
